package com.hexinfo.dmpro.data.transfer.common.controller;

import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import com.hexinfo.dmpro.data.transfer.common.service.ISourceRuleTableViewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
@RequestMapping("/api/source/rule/table/view")
@Api(value = "sourceRuleTableView", tags = "Hive元数据规则视图")
public class SourceRuleTableViewController {

    @Autowired
    private ISourceRuleTableViewService sourceRuleTableViewService;

    @ApiOperation(value = "库集合", notes = "库集合")
    @GetMapping(value = "/databases")
    @AnonymousAccess
    public ResponseEntity<Object> databases() {
        return ResponseEntity.ok(sourceRuleTableViewService.queryDatabaseList());
    }

    @ApiOperation(value = "表集合", notes = "表集合")
    @GetMapping(value = "/tables/{database}")
    @AnonymousAccess
    public ResponseEntity<Object> tables(@PathVariable("database") String database) {
        return ResponseEntity.ok(sourceRuleTableViewService.queryTableNameListByDatabase(database));
    }

    @ApiOperation(value = "源集合", notes = "源集合")
    @GetMapping(value = "/sources")
    @AnonymousAccess
    public ResponseEntity<Object> sources() {
        return ResponseEntity.ok(sourceRuleTableViewService.querySourceList());
    }
}
